﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;

namespace ProjectEuler
{
    internal class Problem22
    {
        private readonly List<string> _names = new List<string>();

        public void Solve()
        {
            var v = AlphaValue("COLIN");
            Debug.WriteLine("COLIN: " + v);

            ReadFile();
            
            var scores = new int[_names.Count];
            
            for (var i = 0; i < _names.Count; i++)
            {
                scores[i] = (i + 1)*AlphaValue(_names[i]);
            }

            var sum = scores.Sum();

            Debug.WriteLine("problem 22: " + sum);
        }

        void ReadFile()
        {
            using (var file = new StreamReader("data\\names_sorted.txt"))
            {
                string line;
                while ((line = file.ReadLine()) != null)
                {
                    _names.Add(line);
                }

                file.Close();
            }
        }

        int AlphaValue(string str)
        {
            var sum = str.Sum(c => Convert.ToInt32((char) c) - Convert.ToInt32('A') + 1);
            return sum;
        }
    }
}